//****************************************************************************
//
// LED blink example
//
//****************************************************************************

#configure board        hu_arm_v4
#configure clcd_lines   2
#configure memory       rom
#configure baudrate     38400

#include "pRTOS.h"
#include "armboard.h"

int main( void ){
   RTOS::run();
   return 0;
}

// end of standard part

void write( const char c ){
   armboard::LCD::char_write( c );
}

void write( const char * s ){
   while( *s != 0 ){ write( *s++ ); }
}

char char_from_mask( int k ){
   for ( int n =0; n < 16; n++ ){
      if( k & ( 1 << n )) return 'A' + n;
   }
   return 'x';
}

class talker : public RTOS::task {
private:
   void main( void ){
      int n = 0;
      for(;;){
         sleep( 50 MS );
         int k = armboard::keypad::read_all(); 
         armboard::LEDs::write( k );
         if( k != 0 ){
            write( "\v::" );
            write( char_from_mask( k ));
         } else {
            if( n % 5 == 0 ){
               write( "\v" );
            }
            write( "=" );
         }   
         if( ++n == 200 ){
            RTOS::display_statistics();
            n=0;
         }
      }
   }
};

talker t;


